﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Web;
using System.Web.Mvc;
using EuroManager.Services;
using EuroManager.Services.Data;
using EuroManager.Services.Implementation;

namespace EuroManager.Presentation.WebPortal.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewData["Message"] = "Welcome to ASP.NET MVC!";
            ViewData["Message2"] = "Blah!!!";

            ISimulatorService simulatorService = new SimulatorService();
            GameData gameData = simulatorService.Play();

            using (MemoryStream stream = new MemoryStream())
            {
                var serializer = new DataContractJsonSerializer(typeof(GameData));
                serializer.WriteObject(stream, gameData);
                ViewData["GameData"] = Convert.ToBase64String(stream.ToArray());
            }

            return View();
        }

        public ActionResult About()
        {
            return View();
        }
    }
}
